home *** CD-ROM | disk | FTP | other *** search
- /* WindowAids.c */ /* C14 Calculator */
-
-
- #include "Globals.h"
-
-
- #include "WindowAids.h"
- #include <Lists.h>
-
- short textJust; /* set by SetWFont */
-
- typedef struct {
- Handle reserved;
- Rect displayRect;
- Byte itemKind;
- Byte dataLen;
- } ItemTemplate, *ItemTPtr;
-
- #define ItemTBaseSize sizeof (ItemTemplate)
-
-
- typedef struct {
- short maxItem;
- ItemTemplate items; /* repeated */
- } WitlTemplate, *WitlTPtr, **WitlTHndl;
-
- void WindowAidsSeg() {}
-
- /*----------*/
- void GetWRect (short itemNr,
- Rect *itemRect)
- {
- WitlTHndl witlHandle;
- ItemTPtr wItemPtr;
- short I;
- short dataSize;
-
- SetRect (itemRect, 0, 0, 16, 16);
- witlHandle = (WitlTHndl) cur->witlHandle;
- if ((witlHandle != NULL)
- && (itemNr <= (**witlHandle).maxItem + 1) ) {
- wItemPtr = &(**witlHandle).items;
- for (I = 1; I <= itemNr - 1; I++) {
- dataSize = wItemPtr->dataLen + (wItemPtr->dataLen & 1);
- wItemPtr = (ItemTPtr) (((Ptr)wItemPtr) + (ItemTBaseSize + dataSize));
- } /*for*/
- *itemRect = wItemPtr->displayRect;
- }
- } /* GetWRect */
-
- typedef struct {
- short header;
- short offset;
- } ictbEntry, *ictbEntryPtr;
-
-
- typedef struct {
- ictbEntry item [5000];
- } WictTemplate, *WictTPtr, **WictTHndl;
-
- typedef struct {
- short fontNum;
- Style typeStyle;
- SignedByte just; /* AppMaker adition */
- short typeSize;
- RGBColor fgColor;
- RGBColor bgColor;
- short xferMode;
- } StyleData, *StyleDataPtr;
-
-
- /* set transfer mode */
- #define doXferMode 0x4000
-
-
-
- /* set font by name */
- #define doByName 0x8000
-
-
- /*----------*/
- void SetWFont (short itemNr)
- {
- WictTHndl wictHandle;
- Ptr wictPtr;
- ictbEntryPtr itemPtr;
- short header;
- short offset;
- StyleDataPtr dataPtr;
- StyleData data;
- StringPtr fontPtr;
- Str255 fontName;
-
- wictHandle = (WictTHndl) cur->wictHandle;
- if (wictHandle != nil) {
- wictPtr = (Ptr) &(**wictHandle);
- itemPtr = &(**wictHandle).item [itemNr - 1];
- header = itemPtr->header;
- offset = itemPtr->offset;
- dataPtr = (StyleDataPtr) (wictPtr + offset);
- data = *dataPtr;
- if ((header & doFont) == 0) {
- data.fontNum = 0;
- } else {
- if ((header & doByName) != 0) {
- fontPtr = (StringPtr) (wictPtr + data.fontNum);
- BlockMove (fontPtr, &fontName, 256);
- GetFNum (fontName, &data.fontNum);
- }
- }
- if ((header & doFace) == 0) {
- data.typeStyle = 0;
- }
- if ((header & doSize) == 0) {
- data.typeSize = 0;
- }
- if ((header & doXferMode) == 0) {
- data.xferMode = srcCopy;
- }
- TextFont (data.fontNum);
- TextFace (data.typeStyle);
- TextMode (data.xferMode);
- TextSize (data.typeSize);
- textJust = data.just;
- }
- } /* SetWFont */
-
-
- /*----------*/
- WindowPtr GetWindow (short windowID)
- {
- if (sysConfig.hasColorQD) {
- return (GetNewCWindow (windowID, NULL, (WindowPtr) -1L));
- } else {
- return (GetNewWindow (windowID, NULL, (WindowPtr) -1L));
- }
- } /* GetWindow */
-
- /*----------*/
- ListHandle NewV1List (Rect bounds,
- WindowPtr parentWindow)
- {
- Rect listBounds;
- Rect dataBounds;
- Point cSize;
- ListHandle list;
-
- listBounds = bounds;
- /*listBounds.right = listBounds.right - 15;*/ /*for scroll bar*/
- SetRect (&dataBounds, 0, 0, 1, 0); /*one column, no rows*/
- SetPt (&cSize, listBounds.right - listBounds.left, 0);
- list = LNew (&listBounds, /*dialog item's box*/
- &dataBounds, /*one column, no rows*/
- cSize, /*cell size: full width, standard height*/
- 0, /*procid - standard text list*/
- parentWindow, /*parent window*/
- false, /*draw it*/
- false, /*has no grow*/
- false, /*no horizontal scroll*/
- false); /*vertical scroll*/
- (**list).selFlags = lOnlyOne + lNoNilHilite;
- return (list);
- } /*NewV1List*/
-
- /*----------*/
- ListHandle NewV1SList (Rect bounds,
- WindowPtr parentWindow)
- {
- Rect listBounds;
- Rect dataBounds;
- Point cSize;
- ListHandle list;
-
- listBounds = bounds;
- listBounds.right = listBounds.right - 15; /*for scroll bar*/
- SetRect (&dataBounds, 0, 0, 1, 0); /*one column, no rows*/
- SetPt (&cSize, listBounds.right - listBounds.left, 0);
- list = LNew (&listBounds, /*dialog item's box*/
- &dataBounds, /*one column, no rows*/
- cSize, /*cell size: full width, standard height*/
- 0, /*procid - standard text list*/
- parentWindow, /*parent window*/
- false, /*draw it*/
- false, /*has no grow*/
- false, /*no horizontal scroll*/
- true); /*vertical scroll*/
- (**list).selFlags = lOnlyOne + lNoNilHilite;
- return (list);
- } /*NewV1SList*/
-
-
- /*----------*/
- Boolean GetListChoice (short *choice,
- ListHandle list)
- {
- Boolean result;
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, 0);
- if (LGetSelect (true, &selectedCell, list)) {
- *choice = selectedCell.v;
- result = true;
- } else {
- *choice = -1;
- result = false;
- }
-
- return (result);
- } /*GetListChoice*/
-
- /*----------*/
- void SetListChoice (short choice,
- ListHandle list)
- {
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, choice);
- LSetSelect (true, selectedCell, list);
- } /*SetListChoice*/
-
- /*----------*/
- void GetListRow (Str255 data,
- short index,
- ListHandle list)
- {
- Cell selectedCell;
- short dataLen;
-
- SetPt (&selectedCell, 0, index);
- dataLen = 255; /*var parameter to LGetCell*/
- LGetCell (&data [1], &dataLen, selectedCell, list);
- data [0] = (char) dataLen;
- } /*GetListRow*/
-
- /*----------*/
- void SetListRow (Str255 data,
- short index,
- ListHandle list)
- {
- Cell selectedCell;
-
- SetPt (&selectedCell, 0, index);
- LSetCell (&data [1], data [0], selectedCell, list);
- } /*SetListRow*/
-
- /*----------*/
- void AddToList (Str255 data,
- ListHandle list)
- {
- short newRow;
-
- #define maxint 32767
-
- newRow = LAddRow (1, maxint, list);
- SetListRow (data, newRow, list);
- } /*AddToList*/
-
- /*----------*/
- void DrawList (ListHandle list)
- {
- PenState savePen;
- Rect frame;
-
- GetPenState (&savePen);
- PenNormal ();
- frame = (**list).rView;
- InsetRect (&frame, -1, -1);
- FrameRect (&frame);
- SetPenState (&savePen);
- LUpdate ((**list).port->visRgn, list);
- } /*DrawList*/
-
-
- /*----------*/
- void EnableControl (ControlHandle theControl,
- Boolean active)
- {
- if (theControl != NULL) {
- if (active) {
- HiliteControl (theControl, 0);
- } else {
- HiliteControl (theControl, 255);
- }
- }
- } /*EnableControl*/
-
-
- /*----------*/
- /* for backwards compatibility:*/
- /*----------*/
- void HiliteScroll (ControlHandle scroll,
- Boolean active)
- {
- EnableControl (scroll, active);
- } /*HiliteScroll*/
-